<template>
  <div class="table_header_btn_box">
    <div class="table_header_btn">
      <el-button text class="btn_box" @click="otherClick('download')" :disabled="isDownloadBtn">
        <i class="icon-downloads1 iconfont-el icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.download') }} </span>
      </el-button>

      <el-button text class="btn_box" @click="otherClick('copy')" :disabled="isCopyBtn">
        <i class="icon-document-copy iconfont-el icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.copy') }} </span>
      </el-button>

      <el-button text class="btn_box" @click="otherClick('move')" :disabled="isMoveBtn">
        <!-- <svg-icon icon-class="move" class="icon"></svg-icon> -->
        <i class="iconfont-el icon-scissors"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.move') }} </span>
      </el-button>

      <el-button text class="btn_box" @click="otherClick('delete')" :disabled="isDeleteBtn">
        <svg-icon icon-class="trash" class="icon"></svg-icon>
        <span class="name">{{ pageType != 'enterprise' ? $t('teamDoc.rightBtnList.delete') : $t('teamDoc.rightBtnList.invalid') }} </span>
      </el-button>

      <el-button text v-if="tableRowArray.length == 1" class="btn_box" @click="otherClick('collection')">
        <svg-icon v-if="tableRowArray[0].collection == '1'" icon-class="collect-fill" class="icon_size"></svg-icon>
        <svg-icon v-else icon-class="collect" class="icon_size"></svg-icon>
        <span class="name"
          >{{ tableRowArray[0].collection == 0 ? $t('teamDoc.rightBtnList.collect') : $t('teamDoc.rightBtnList.cancelCollect') }}
        </span>
      </el-button>

      <!-- 个人单个文件添加标签的操作 -->
      <el-button text v-if="tableRowArray.length == 1 && props.pageType != 'team'" class="btn_box" @click="otherClick('label')">
        <i class="icon-collection iconfont-el icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.tags') }}</span>
      </el-button>

      <!-- 个人多个文件添加标签的操作 -->
      <el-button text v-if="tableRowArray.length != 1 && props.pageType != 'team'" class="btn_box" @click="otherClick('label')">
        <i class="iconfont-el icon-collection icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.tags') }}</span>
      </el-button>

      <!-- 企业多个文件添加标签的操作 -->

      <!-- <el-button v-if="tableRowArray.length != 1 && pageType == 'enterprise'"   class="btn_box" @click="otherClick('enterpriseLabel')">
        <i class="iconfont-el icon-collection icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.tagDocuments') }}</span>
      </el-button> -->

      <el-button text class="btn_box" @click="otherClick('outEnjoy')" :disabled="isOutEnjoyBtn">
        <i class="iconfont-el icon-receiving icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.distribute') }}</span>
      </el-button>

      <el-button text class="btn_box" v-if="tableRowArray.length == 1" @click="otherClick('enjoy')" :disabled="isShareBtn">
        <i class="iconfont-el icon-share icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.share') }}</span>
      </el-button>

      <el-button text v-if="tableRowArray.length == 1" class="btn_box" @click="otherClick('detail')">
        <i class="iconfont-el icon-view icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.details') }}</span>
      </el-button>

      <!-- <el-button   class="btn_box" @click="otherClick('exportBtn')" v-if="isFolderOnly">
        <i class="iconfont-el icon-upload2 icon"></i>
        <span class="name">{{ $t('teamDoc.rightBtnList.export') }}</span>
      </el-button> -->

      <el-button text v-if="tableRowArray.length == 1 && tableRowArray[0].type == 'file'" class="btn_box" @click="otherClick('detail')">
        <svg-icon icon-class="history" class="icon" />
        <span class="name">{{ $t('teamDoc.rightBtnList.versions') }}</span>
      </el-button>

      <!-- AI部分 -->
      <div class="btn_box" v-if="MenuisShow() && isTypeShow && tableRowArray.length == 1 && props.pageType !== 'team'">
        <el-dropdown @command="moreListCommand" trigger="click">
          <div class="btn_box">
            <svg-icon icon-class="ai_chat3" class="icon_size icon_mr" />
            {{ $t('teamDoc.rightBtnList.aiFunction') }}
            <!-- <i class="el-icon-caret-right"></i> -->
          </div>

          <template #dropdown>
            <el-dropdown-menu>
              <!-- <el-dropdown-item class="Dropdown_item_menu item_border_bottom" command="AiQA">
                <svg-icon icon-class="ai_chat3" class="icon_size icon_mr" />
                <span>{{ $t('teamDoc.rightBtnList.aiChat') }}</span>
              </el-dropdown-item> -->

              <el-dropdown-item class="Dropdown_item_menu" command="AiSummary">
                <svg-icon icon-class="gongzuozongjie" class="icon_size icon_mr" />
                <span>{{ $t('teamDoc.rightBtnList.aiSummarize') }}</span>
              </el-dropdown-item>

              <el-dropdown-item class="Dropdown_item_menu" command="AiAbstract">
                <svg-icon icon-class="tiaocha" class="icon_size icon_mr" />
                <span>{{ $t('teamDoc.rightBtnList.aiAbstract') }}</span>
              </el-dropdown-item>

              <el-dropdown-item class="Dropdown_item_menu item_border_bottom" command="AiExtract">
                <svg-icon icon-class="zhishichouqu" class="icon_size icon_mr" />
                <span>{{ $t('teamDoc.rightBtnList.aiExtract') }}</span>
              </el-dropdown-item>

              <!-- <el-dropdown-item class="Dropdown_item_menu" command="AiRead">
                <svg-icon icon-class="huiyi" class="icon_size icon_mr" />
                <span>{{ $t('teamDoc.rightBtnList.aiRead') }}</span>
              </el-dropdown-item> -->

              <el-dropdown-item class="Dropdown_item_menu" command="AiTranslate">
                <svg-icon icon-class="translate" class="icon_size icon_mr" />
                <span>AI翻译</span>
              </el-dropdown-item>

              <!-- <el-dropdown-item class="Dropdown_item_menu" command="AiDrill">
                <svg-icon icon-class="xlsq-high-copy" class="icon_size icon_mr" />
                <span>{{ $t('teamDoc.rightBtnList.aiDrill') }}</span>
              </el-dropdown-item> -->
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>

      <!-- 更多  v-if="tableRowArray.length == 1"-->
      <div class="btn_box">
        <el-dropdown @command="moreListCommand">
          <div class="btn_box">
            <i class="iconfont-el icon-more-outline"></i>
            <span class="name">{{ $t('teamDoc.rightBtnList.more') }}</span>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item class="Dropdown_item_menu" v-if="isShowMenu() && tableRowArray.length == 1" :icon="User" command="templateLibrary">
                {{ $t('teamDoc.rightBtnList.personalTemplateLibrary') }}
              </el-dropdown-item>

              <el-dropdown-item
                class="Dropdown_item_menu"
                v-if="isShowMenu() && tableRowArray.length == 1"
                :icon="FullScreen"
                command="publicTemplateLibrary"
              >
                {{ $t('teamDoc.rightBtnList.commonTemplateLibrary') }}
              </el-dropdown-item>

              <el-dropdown-item class="Dropdown_item_menu" :icon="Plus" command="enterpriseLabel">
                {{ $t('teamDoc.rightBtnList.submitEnterprise') }}
              </el-dropdown-item>

              <el-dropdown-item class="Dropdown_item_menu" command="Expert" v-if="isMenuShow()" :icon="Upload"> 专家知识库 </el-dropdown-item>

              <el-dropdown-item class="Dropdown_item_menu" command="AgainExpert" v-if="isExpert()" :icon="Upload">
                重新提交专家知识库
              </el-dropdown-item>

              <!-- <el-dropdown-item
                v-if="isShowMenu() && tableRowArray.length == 1"
                class="Dropdown_item_menu_more"
                icon="el-icon-circle-plus-outline"
                command="joinTemplates"
              >
                {{ $t('teamDoc.rightBtnList.joinTemplates') }}
                <i class="el-icon-caret-right"></i>
                <div class="info">
                  <p @click="otherClick('templateLibrary')">{{ $t('teamDoc.rightBtnList.personalTemplateLibrary') }}</p>
                  <p @click="otherClick('publicTemplateLibrary')">{{ $t('teamDoc.rightBtnList.commonTemplateLibrary') }}</p>
                </div>
              </el-dropdown-item> -->
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>

      <!-- <div v-if="pageType == 'self' || pageType == 'team'" class="btn_box">
        <el-dropdown @command="moreListCommand">
          <div class="btn_box">
            <i class="iconfont-el icon-more-outline"></i>
            <span class="name">{{ $t('teamDoc.rightBtnList.more') }}</span>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item class="Dropdown_item_menu" v-if="pageType == 'self'" :icon="Plus" command="submitFileToTeam">
                {{ $t('teamDoc.rightBtnList.commitToTeam') }}
              </el-dropdown-item>
              <el-dropdown-item class="Dropdown_item_menu" :icon="Plus" command="enterpriseLabel">
                {{ $t('teamDoc.rightBtnList.submitEnterprise') }}
              </el-dropdown-item>

              <el-dropdown-item
                v-if="isShowMenu() && tableRowArray.length == 1"
                class="Dropdown_item_menu_more"
                icon="el-icon-circle-plus-outline"
                command="joinTemplates"
              >
                {{ $t('teamDoc.rightBtnList.joinTemplates') }}
                <i class="el-icon-caret-right"></i>
                <div class="info">
                  <p @click="otherClick('templateLibrary')">{{ $t('teamDoc.rightBtnList.personalTemplateLibrary') }}</p>
                  <p @click="otherClick('publicTemplateLibrary')">{{ $t('teamDoc.rightBtnList.commonTemplateLibrary') }}</p>
                </div>
              </el-dropdown-item>
              <el-dropdown-item v-if="fileFerryHidden()" class="Dropdown_item_menu" icon="el-icon-sort" command="ferryFile">
                {{ $t('teamDoc.rightBtnList.inOut') }}
              </el-dropdown-item>

              <el-dropdown-item v-if="pageType == 'self'" class="Dropdown_item_menu" command="invitationEdit" :icon="Link">
                {{ $t('teamDoc.rightBtnList.inviteCollaboration') }}
              </el-dropdown-item>

              <el-dropdown-item
                v-if="pageType == 'team' && tableRowArray[0].type == 'file'"
                class="Dropdown_item_menu"
                icon="el-icon-data-analysis "
                command="addTrain"
              >
                {{ $t('teamDoc.rightBtnList.joinTrain') }}
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div> -->

      <!-- <el-button v-if="isFileLibrary"   class="btn_box" @click="otherClick('fileLibrary')">
        <i class="el-icon-upload2" />
        <span class="name">{{ $t('teamDoc.rightBtnList.fileIntoStorage') }}</span>
      </el-button> -->

      <!-- <el-button   class="btn_box" :disabled="isSyncAi" @click="otherClick('syncKnowledge')">
        <svg-icon icon-class="xlsq-high-copy" class="icon_size icon_mr" />
        <span class="name">{{ $t('teamDoc.rightBtnList.aiDrill') }}</span>
      </el-button> -->
    </div>
  </div>
</template>

<script setup lang="ts" name="table-header-btn">
import { ApiAIShow } from '@/api/personDoc/aiApi';
import { Plus, Link, FullScreen, User, Upload } from '@element-plus/icons-vue';
import { useTeamRoleStore } from '@/store/modules/teamRole';
const teamRoleStore = useTeamRoleStore();
const { proxy } = getCurrentInstance() as any;

const props = defineProps({
  pageType: {
    type: String,
    default: 'self' //enterprise:企业,team:团队,self:个人
  },

  tableRowArray: {
    //用于文件增强
    type: Array,
    default: () => {
      return [];
    }
  }
});
const tableRowArray: any = ref([]);
watch(
  () => props.tableRowArray,
  (newValue, oldValue) => {
    tableRowArray.value = newValue;
  },
  { deep: true, immediate: true }
);

//同步到AI模型
const isSyncAi = computed(() => {
  if (props.pageType == 'enterprise') {
    // return !proxy.$yuUtils.documentsPermissionFunc(["syncAi"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
  } else if (props.pageType == 'team') {
    return false;
  } else {
    return false;
  }
});
// 归档入库的显示条件
const isFileLibrary = computed(() => {
  let isShow = false;
  // let res = this.tableRowArray.filter((item) => item.type == "folder");
  // if (this.pageType == "enterprise" && this.tableRowArray.length > 0 && res.length == 0 && this.$yuUtils.LicenseInfoFunc("archives:list")) {
  //   isShow = true;
  // }
  return isShow;
});
// 检查 tableRowArray 中的每一个元素是否都是 'folder',不是就不显示
const isFolderOnly = computed(() => {
  return tableRowArray.value.every((item) => item.type === 'folder');
});
const isDownloadBtn = computed(() => {
  if (props.pageType == 'enterprise') {
    // return !this.$yuUtils.documentsPermissionFunc(["download"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
  } else if (props.pageType == 'team') {
    return !proxy.$yuUtils.documentsPermissionFunc(['download'], teamRoleStore.myTeamFileRoleList);
  } else {
    return false;
  }
});
const isCopyBtn = computed(() => {
  if (props.pageType == 'enterprise') {
    // return !this.$yuUtils.documentsPermissionFunc(["download"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
  } else if (props.pageType == 'team') {
    return !proxy.$yuUtils.documentsPermissionFunc(['copy'], teamRoleStore.myTeamFileRoleList);
  } else {
    return false;
  }
});
const isMoveBtn = computed(() => {
  if (props.pageType == 'enterprise') {
    // return !this.$yuUtils.documentsPermissionFunc(["download"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
  } else if (props.pageType == 'team') {
    return !proxy.$yuUtils.documentsPermissionFunc(['move'], teamRoleStore.myTeamFileRoleList);
  } else {
    return false;
  }
});
const isDeleteBtn = computed(() => {
  if (props.pageType == 'enterprise') {
    // return !this.$yuUtils.documentsPermissionFunc(["download"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
  } else if (props.pageType == 'team') {
    return !proxy.$yuUtils.documentsPermissionFunc(['delete'], teamRoleStore.myTeamFileRoleList);
  } else {
    return false;
  }
});
const isOutEnjoyBtn = computed(() => {
  if (props.pageType == 'enterprise') {
    // return !this.$yuUtils.documentsPermissionFunc(["download"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
  } else if (props.pageType == 'team') {
    return !proxy.$yuUtils.documentsPermissionFunc(['distribute'], teamRoleStore.myTeamFileRoleList);
  } else {
    return false;
  }
});
const isShareBtn = computed(() => {
  if (props.pageType == 'enterprise') {
    // return !this.$yuUtils.documentsPermissionFunc(["download"], this.$store.state.enterpriseRole.enterpriseMyRoleList);
  } else if (props.pageType == 'team') {
    return !proxy.$yuUtils.documentsPermissionFunc(['share'], teamRoleStore.myTeamFileRoleList);
  } else {
    return false;
  }
});
const emit = defineEmits(['otherClick', 'fileEnhanceCommand']);

const otherClick = (str) => {
  // 这个方法在globalMixins.js文件里
  emit('otherClick', str);
};
// 更多
const moreListCommand = (command: any) => {
  emit('otherClick', command);
};
//文件增强
const fileEnhanceCommand = (str: any) => {
  // 密级
  if (str == 'safety') {
    // this.dialogSafety = true;
  } else {
    emit('fileEnhanceCommand', str);
  }
};
// 内外摆渡按钮显示判断
const fileFerryHidden = () => {
  return false;
  // if (this.$store.state.user.ferrySwitch && this.pageType == "self" && this.$yuUtils.vifpermissionRoles(["admin", "ferry:list"])) {
  //   return !false;
  // } else {
  //   return !true;
  // }
};
// 模板库菜单显示判断
const isShowMenu = () => {
  if (
    tableRowArray.value[0]?.type === 'file' &&
    ['ppt', 'pptx', 'excel', 'docx', 'doc', 'xlsx', 'xls', 'txt', 'pdf'].includes(tableRowArray.value[0].suffix)
  ) {
    return true;
  } else {
    return false;
  }
};

//判断文件类型(pdf的图片暂时无法识别,可以了就用isShowMenu()这个方法)
const MenuisShow = () => {
  if (
    tableRowArray.value[0]?.type === 'file' &&
    ['ppt', 'pptx', 'excel', 'docx', 'doc', 'xlsx', 'xls', 'txt'].includes(tableRowArray.value[0].suffix)
  ) {
    return true;
  } else {
    return false;
  }
};

// 提交到专家知识库的显示条件
const isMenuShow = () => {
  // 检查是否同时存在 expert == 'true' 和 expert != 'true'
  const hasExpertTrue = tableRowArray.value.some((row) => row.expert == 'true');
  const hasExpertNotTrue = tableRowArray.value.some((row) => row.expert != 'true');
  if (hasExpertTrue && hasExpertNotTrue) {
    return false; // 如果同时存在，返回 false，不显示
  }

  // 第一层判断：检查是否有文件且文件后缀符合要求
  const hasValidFile = tableRowArray.value.some(
    (row) =>
      row.expert != 'true' && row.type == 'file' && ['csv', 'md', 'html', 'docx', 'xlsx', 'xls', 'txt', 'pdf', 'markdown', 'htm'].includes(row.suffix)
  );

  // 第一层改进：检查是否存在无效后缀的文件
  const hasInvalidFile = tableRowArray.value.some(
    (row) => row.type == 'file' && !['csv', 'md', 'html', 'docx', 'xlsx', 'xls', 'txt', 'pdf', 'markdown', 'htm'].includes(row.suffix)
  );

  // 第一层改进：检查是否有文件夹
  const Folderhas = tableRowArray.value.some((row) => row.type == 'folder');

  // 如果有符合要求的文件且没有无效后缀的文件，并且没有文件夹，则放行
  if (hasValidFile && !hasInvalidFile && !Folderhas) {
    return true; // 放行
  }

  // 第二层判断：检查是否有文件夹且文件夹长度为 1
  const hasFolderWithOneItem = tableRowArray.value.some((row) => row.type == 'folder' && tableRowArray.value.length == 1 && row.expert != 'true');

  if (hasFolderWithOneItem) {
    return true; // 放行
  }

  let hasFile = false;
  let hasFolder = false;

  // 遍历 tableRowArray.value，检查是否同时包含 'file' 和 'folder'
  for (const row of tableRowArray.value) {
    if (row.type === 'file') {
      hasFile = true;
    }
    if (row.type === 'folder') {
      hasFolder = true;
    }

    // 如果两者同时存在，提前返回 false
    if (hasFile && hasFolder) {
      return false; // 不放行
    }
  }

  // 其他情况都不放行
  return false;
};

// 提交到专家知识库的显示条件
const isExpert = () => {
  // 检查是否同时存在 expert == 'true' 和 expert != 'true'
  const hasExpertTrue = tableRowArray.value.some((row) => row.expert == 'true');
  const hasExpertNotTrue = tableRowArray.value.some((row) => row.expert != 'true');
  if (hasExpertTrue && hasExpertNotTrue) {
    return false; // 如果同时存在，返回 false，不显示
  }

  // 第一层判断：检查是否有文件且文件后缀符合要求
  const hasValidFile = tableRowArray.value.some(
    (row) =>
      row.expert == 'true' && row.type == 'file' && ['csv', 'md', 'html', 'docx', 'xlsx', 'xls', 'txt', 'pdf', 'markdown', 'htm'].includes(row.suffix)
  );

  // 第一层改进：检查是否存在无效后缀的文件
  const hasInvalidFile = tableRowArray.value.some(
    (row) => row.type == 'file' && !['csv', 'md', 'html', 'docx', 'xlsx', 'xls', 'txt', 'pdf', 'markdown', 'htm'].includes(row.suffix)
  );

  // 第一层改进：检查是否有文件夹
  const Folderhas = tableRowArray.value.some((row) => row.type == 'folder');

  // 如果有符合要求的文件且没有无效后缀的文件，并且没有文件夹，则放行
  if (hasValidFile && !hasInvalidFile && !Folderhas) {
    return true; // 放行
  }

  // 第二层判断：检查是否有文件夹且文件夹长度为 1
  const hasFolderWithOneItem = tableRowArray.value.some((row) => row.type == 'folder' && tableRowArray.value.length == 1 && row.expert == 'true');

  if (hasFolderWithOneItem) {
    return true; // 放行
  }

  let hasFile = false;
  let hasFolder = false;

  // 遍历 tableRowArray.value，检查是否同时包含 'file' 和 'folder'
  for (const row of tableRowArray.value) {
    if (row.type === 'file') {
      hasFile = true;
    }
    if (row.type === 'folder') {
      hasFolder = true;
    }

    // 如果两者同时存在，提前返回 false
    if (hasFile && hasFolder) {
      return false; // 不放行
    }
  }

  // 其他情况都不放行
  return false;
};

//提交到专家知识库的显示条件
const isMenuShow0 = () => {
  // 第一层判断：检查是否有文件且文件后缀符合要求
  const hasValidFile = tableRowArray.value.some(
    (row) =>
      row.expert != 'true' && row.type == 'file' && ['csv', 'md', 'html', 'docx', 'xlsx', 'xls', 'txt', 'pdf', 'markdown', 'htm'].includes(row.suffix)
  );

  // 第一层改进：检查是否存在无效后缀的文件
  const hasInvalidFile = tableRowArray.value.some(
    (row) => row.type == 'file' && !['csv', 'md', 'html', 'docx', 'xlsx', 'xls', 'txt', 'pdf', 'markdown', 'htm'].includes(row.suffix)
  );

  // 第一层改进：检查是否有文件夹
  const Folderhas = tableRowArray.value.some((row) => row.type == 'folder');

  // 如果有符合要求的文件且没有无效后缀的文件，并且没有文件夹，则放行
  if (hasValidFile && !hasInvalidFile && !Folderhas) {
    // console.log(11);
    return true; // 放行
  }

  // 第二层判断：检查是否有文件夹且文件夹长度为 1
  const hasFolderWithOneItem = tableRowArray.value.some((row) => row.type == 'folder' && tableRowArray.value.length == 1);

  // 调试，输出符合条件的文件夹
  if (hasFolderWithOneItem) {
    // console.log(22);
    return true; // 放行
  }

  let hasFile = false;
  let hasFolder = false;

  // 遍历 tableRowArray.value，检查是否同时包含 'file' 和 'folder'
  for (const row of tableRowArray.value) {
    if (row.type === 'file') {
      hasFile = true;
    }
    if (row.type === 'folder') {
      hasFolder = true;
    }

    // 如果两者同时存在，提前返回 false
    if (hasFile && hasFolder) {
      // console.log(33);
      return false; // 不放行
    }
  }

  // 其他情况都不放行
  // console.log(44);
  return false;
};

//提交到专家知识库的显示条件
const isExpert0 = () => {
  // 第一层判断：检查是否有文件且文件后缀符合要求
  const hasValidFile = tableRowArray.value.some(
    (row) =>
      row.expert == 'true' && row.type == 'file' && ['csv', 'md', 'html', 'docx', 'xlsx', 'xls', 'txt', 'pdf', 'markdown', 'htm'].includes(row.suffix)
  );

  // 第一层改进：检查是否存在无效后缀的文件
  const hasInvalidFile = tableRowArray.value.some(
    (row) => row.type == 'file' && !['csv', 'md', 'html', 'docx', 'xlsx', 'xls', 'txt', 'pdf', 'markdown', 'htm'].includes(row.suffix)
  );

  // 第一层改进：检查是否有文件夹
  const Folderhas = tableRowArray.value.some((row) => row.type == 'folder');

  // 如果有符合要求的文件且没有无效后缀的文件，并且没有文件夹，则放行
  if (hasValidFile && !hasInvalidFile && !Folderhas) {
    // console.log(11);
    return true; // 放行
  }

  // 第二层判断：检查是否有文件夹且文件夹长度为 1
  const hasFolderWithOneItem = tableRowArray.value.some((row) => row.type == 'folder' && tableRowArray.value.length == 1);

  // 调试，输出符合条件的文件夹
  if (hasFolderWithOneItem) {
    // console.log(22);
    return true; // 放行
  }

  let hasFile = false;
  let hasFolder = false;

  // 遍历 tableRowArray.value，检查是否同时包含 'file' 和 'folder'
  for (const row of tableRowArray.value) {
    if (row.type === 'file') {
      hasFile = true;
    }
    if (row.type === 'folder') {
      hasFolder = true;
    }

    // 如果两者同时存在，提前返回 false
    if (hasFile && hasFolder) {
      // console.log(33);
      return false; // 不放行
    }
  }

  // 其他情况都不放行
  // console.log(44);
  return false;
};

const isTypeShow = ref(false) as any;

// 判断是否显示AI
const getIsShow = () => {
  let oParam = {
    configKey: 'personal_chat'
  };
  ApiAIShow(oParam).then((res) => {
    isTypeShow.value = res;
  });
};

onMounted(() => {
  getIsShow();
});
</script>

<style scoped lang="scss">
.table_header_btn_box {
  // height: 34px;
}

.table_header_btn {
  height: 34px;
  display: flex;
  align-items: center;
  position: relative;
  z-index: 800;
  padding: 0;
}

.btn_box {
  display: flex !important;
  align-items: center !important;
  color: #666;
  font-size: 14px;
  margin-right: 6px;
  cursor: pointer;
  padding: 0;
  line-height: normal;

  .icon {
    color: #999;
    font-size: 15px;
    margin-top: 2px;
  }

  .name {
    margin-left: 6px;
  }

  &:hover {
    background: none !important;
    color: #6698ff;

    .icon {
      color: #6698ff;
    }
  }
}

.el-button.is-disabled.el-button--text {
  color: #c0c4cc;
  cursor: not-allowed;

  .icon {
    color: #c0c4cc;
  }

  &:hover {
    color: #c0c4cc;

    .icon {
      color: #c0c4cc;
    }
  }
}

.Dropdown_item_menu {
  padding-top: 5px !important;
  padding-bottom: 5px !important;
  font-size: 14px !important;

  &:hover {
    background-color: #f5f5f5 !important;
    color: #606266;
  }
}

.Dropdown_item_menu_more {
  position: relative;
  padding-top: 5px !important;
  padding-bottom: 5px !important;
  font-size: 14px !important;

  .info {
    display: none;
  }

  &:hover {
    .info {
      display: block;
      position: absolute;
      left: 120px;
      top: -50%;
      width: 100px;
      height: 100px;
      background-color: white;
      padding: 10px 0px;

      p {
        margin: 0;
        padding: 0;
        text-align: center;
        line-height: 35px;

        &:hover {
          background-color: #f5f5f5 !important;
          color: #606266;
        }
      }
    }

    background-color: #f5f5f5 !important;
    color: #606266;
  }
}

:deep(.item_border_bottom) {
  border-bottom: 1px solid #eee;
}

.icon_mr {
  margin-right: 6px;
}
</style>
